//package com.alibaba.cirtus.ots.application.app.ability.facade;
//
//import com.alibaba.cz.base.tool.log.Log;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.alibaba.lattice2.epoch.sdk.model.Result;
//import com.epoch.app.bcots.model.dto.*;
//import com.epoch.app.bcots.service.BaseDataService;
//import com.epoch.app.bcots.service.PlatformEnhanceService;
//import com.epoch.app.bcots.service.UnifiedInventoryService;
//import com.epoch.app.otsapplicationappsdk.transfercreate.dto.AsyncRequest;
//import com.epoch.app.otsapplicationappsdk.transfercreate.dto.InitRequest;
//import com.epoch.app.otsapplicationappsdk.transfercreate.dto.SubmitRequest;
//import com.epoch.app.otsapplicationappsdk.transfercreate.service.TransferCreateService;
//import com.epoch.app.otsplatformenhance.goodsfavorites.dto.QueryGoodsFavoritesRequest;
//import com.epoch.app.otsplatformenhance.goodsfavorites.model.GoodsFavorites;
//import com.epoch.app.otsplatformenhance.goodsfavorites.service.GoodsFavoritesService;
//import com.epoch.app.otsunifiedinventory.api.allocateapplyorderdropdownselection.dto.QueryBranchCustomersRequest;
//import com.epoch.app.otsunifiedinventory.api.allocateapplyorderdropdownselection.service.AllocateApplyOrderDropDownSelectionService;
//import com.epoch.app.otsunifiedinventory.api.allocateapplyorderread.service.AllocateApplyOrderReadService;
//import com.epoch.app.otsunifiedinventory.api.allocateapplyorderwrite.service.AllocateApplyOrderWriteService;
//import com.epoch.app.otsunifiedinventory.api.forecastwarehouse.dto.QueryDeliveryWarehouseByTypeRequest;
//import com.epoch.app.otsunifiedinventory.api.forecastwarehouse.dto.QueryReceivingWarehouseByTypeRequest;
//import com.epoch.app.otsunifiedinventory.api.forecastwarehouse.service.ForecastWarehouseService;
//import com.epoch.app.otsunifiedinventory.dto.request.QueryAllocateApplyOrderRequest;
//import com.epoch.app.otsunifiedinventory.dto.response.AllocateApplyOrderDetailDTO;
//import com.epoch.app.otsunifiedinventory.dto.response.DeliveryWarehouseChoiceDTO;
//import com.epoch.app.otsunifiedinventory.model.dto.AllocateApplyOrderCreateDTO;
//import com.epoch.app.otsunifiedinventory.model.dto.AllocateApplyOrderDetailCreateDTO;
//import com.epoch.app.otsunifiedinventory.model.dto.AllocateApplyOrderUpdateDTO;
//import com.epoch.app.otsunifiedinventory.model.dto.BranchCustomersDTO;
//import com.epoch.app.otsunifiedinventory.service.OtsUnifiedInventoryService;
//import com.google.common.collect.Lists;
//import org.apache.commons.collections4.CollectionUtils;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.util.*;
//
//
//@Service
//public class TransferCreateServiceImpl  implements TransferCreateService {
//
//    private static Log log = Log.getLogger(TransferCreateServiceImpl.class);
//
//    @Resource
//    AllocateApplyOrderReadService allocateApplyOrderReadService;
//
//    @Resource
//    AllocateApplyOrderWriteService allocateApplyOrderWriteService;
//
//    @Resource
//    BaseDataService baseDataService;
//
//    @Resource
//    OtsUnifiedInventoryService otsUnifiedInventoryService;
//
//    @Resource
//    AllocateApplyOrderDropDownSelectionService allocateApplyOrderDropDownSelectionService;
//    @Resource
//    PlatformEnhanceService platformEnhanceService;
//
//    @Resource
//    ForecastWarehouseService forecastWarehouseService;
//
//    @Resource
//    UnifiedInventoryService unifiedInventoryService;
//
//    @Resource
//    private GoodsFavoritesService favoritesService;
//
//
//    @Override
//    public Object init(InitRequest initRequest) {
//        log.info("调拨预报单创建渲染 请求参数 {} " , JSONObject.toJSONString(initRequest));
//        JSONObject result = new JSONObject();
//        JSONObject data = new JSONObject();
//        try {
//            //当前用户收藏夹货品
//            List goodsFavoritesList = new ArrayList();
//            try {
//                Result<List<GoodsFavorites>> listResult = favoritesService.queryGoodsFavorites(new QueryGoodsFavoritesRequest());
//                if (Objects.nonNull(listResult)&& CollectionUtils.isNotEmpty(listResult.getResult())){
//                    GoodsFavorites goodsFavorites = listResult.getResult().get(0);
//                    JSONArray goodsList = JSONArray.parseArray(goodsFavorites.getGoodsList());
//                    if (CollectionUtils.isNotEmpty(goodsList)) {
//                        for (Object goodsObj : goodsList) {
//                            JSONObject goodsJson = (JSONObject) JSONObject.toJSON(goodsObj);
//                            goodsFavoritesList.add(goodsJson.getString("goodsCode"));
//                        }
//                    }
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//
//
//            Result<AllocateApplyOrderDetailDTO> callApiResult = null;
//            if (initRequest.getCode() != null) {
//                try {
//                    QueryAllocateApplyOrderRequest queryAllocateApplyOrderRequest = new QueryAllocateApplyOrderRequest();
//                    queryAllocateApplyOrderRequest.setCode(initRequest.getCode());
//                    callApiResult = allocateApplyOrderReadService.queryAllocateApplyOrderByCode(queryAllocateApplyOrderRequest);
//                    data.put("detailData",callApiResult.getResult());
//                } catch (Exception e) {
//                    log.info("调拨预报单创建渲染 调拨预报单详情API异常");
//                    e.printStackTrace();
//                }
//            }
//
//
//            try {
//                //单据类型
//                Object  allocateApplyOrderDropDownSelection = allocateApplyOrderDropDownSelectionService.queryDocumentType();
//                data.put("allocationType",allocateApplyOrderDropDownSelection);
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 单据类型API异常");
//                e.printStackTrace();
//            }
//
//
//            try {
//                //提报组织
//                LoginEmployeeSubmissionOrganizationSelectResponse loginEmployeeSubmissionOrganizationSelectResponse = baseDataService.loginEmployeeSubmissionOrganizationSelect(new LoginEmployeeSubmissionOrganizationSelectRequest());
//                log.info("调拨预报单创建渲染 提报组织结果 {} ",JSONObject.toJSONString(loginEmployeeSubmissionOrganizationSelectResponse));
//                data.put("organizationSelect",loginEmployeeSubmissionOrganizationSelectResponse.getResult());
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 提报组织API异常");
//                e.printStackTrace();
//            }
//
//
//            try {
//                //收货仓 类型 组织
//                QueryReceivingWarehouseByTypeRequest queryReceivingWarehouseByTypeRequest = new QueryReceivingWarehouseByTypeRequest();
//                //callApiResult不为空为编辑状态，发货仓下拉框数据为该单子的单据类型和组织维度下的数据
//                if (callApiResult != null && callApiResult.getResult() != null &&
//                    callApiResult.getResult().getType() != null && callApiResult.getResult().getApplyOrg() != null) {
//                    queryReceivingWarehouseByTypeRequest.setType(callApiResult.getResult().getType());
//                    queryReceivingWarehouseByTypeRequest.setApplyOrgId(String.valueOf(callApiResult.getResult().getApplyOrg()));
//                } else {
//                    queryReceivingWarehouseByTypeRequest.setType("1");
//                }
//                log.info("调拨预报单创建渲染 收货仓API入参 {} ",JSONObject.toJSONString(queryReceivingWarehouseByTypeRequest));
//                Result<List<DeliveryWarehouseChoiceDTO>> forecastWarehouseResult = forecastWarehouseService.queryReceivingWarehouseByType(queryReceivingWarehouseByTypeRequest);
//                log.info("调拨预报单创建渲染 收货仓API出参 {} ",JSONObject.toJSONString(forecastWarehouseResult));
//                data.put("receivingWarehouse",forecastWarehouseResult.getResult());
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 收货仓API异常");
//                e.printStackTrace();
//            }
//
//            try {
//                //货品组
//                GetScItemGroupSelectResponse scItemGroupSelect = baseDataService.getScItemGroupSelect();
//                data.put("scItemGroupSelect",scItemGroupSelect.getResult());
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 货品组API异常");
//                e.printStackTrace();
//            }
//
//
//            try {
//                //发货仓 单据类型
//                QueryDeliveryWarehouseByTypeRequest queryDeliveryWarehouseByTypeRequest = new QueryDeliveryWarehouseByTypeRequest();
//                //callApiResult不为空为编辑状态，发货仓下拉框数据为该单子的单据类型和组织维度下的数据
//                if (callApiResult != null && callApiResult.getResult() != null && callApiResult.getResult().getType() != null) {
//                    queryDeliveryWarehouseByTypeRequest.setType(callApiResult.getResult().getType());
//                } else {
//                    queryDeliveryWarehouseByTypeRequest.setType("1");
//                }
//                log.info("调拨预报单创建渲染 发货仓API入参 {} ",JSONObject.toJSONString(queryDeliveryWarehouseByTypeRequest));
//                Result<List<DeliveryWarehouseChoiceDTO>> deliveryWarehouse = forecastWarehouseService.queryDeliveryWarehouseByType(queryDeliveryWarehouseByTypeRequest);
//                log.info("调拨预报单创建渲染 发货仓API出参 {} ",JSONObject.toJSONString(deliveryWarehouse));
//                data.put("deliveryWarehouse",deliveryWarehouse.getResult());
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 发货仓API异常");
//                e.printStackTrace();
//            }
//
//            try {
//                //货品明细
//                //前端透传常用货品code，下发到接口返回常用货品类目
//                QueryGoodsListRequest queryGoodsListRequest = new QueryGoodsListRequest();
//                queryGoodsListRequest.setRecentlyUsedItemIdList(initRequest.getGoodsIdList());
//                if (CollectionUtils.isNotEmpty(goodsFavoritesList)) {
//                    queryGoodsListRequest.setGoodsFavoritesList(goodsFavoritesList);
//                }
//                Result<List<QueryGoodsListResponse>> queryGoodsListResponse = platformEnhanceService.queryGoodsList(queryGoodsListRequest);
//                data.put("goodsList",queryGoodsListResponse.getResult());
////                data.put("goodsList",buildGoodsList(queryGoodsListResponse.getResult(),initRequest.getGoodsIdList()));
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 货品明细API异常");
//                e.printStackTrace();
//            }
//
//
//            try {
//                //运输方式
//                Object transportModeMap = otsUnifiedInventoryService.transportModeReadServiceImplQueryTransportMode();
//                JSONObject transportJson = (JSONObject)JSONObject.toJSON(transportModeMap);
//                data.put("transport",transportJson.getJSONArray("result"));
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 运输方式API异常");
//                e.printStackTrace();
//            }
//
//            try {
//                //分公司客户
//                Result<List<BranchCustomersDTO>> branchCustomers  = allocateApplyOrderDropDownSelectionService.queryBranchCustomers(new QueryBranchCustomersRequest());
//                log.info("调拨预报单创建渲染 分公司客户结果 {} ",JSONObject.toJSONString(branchCustomers));
//                if (branchCustomers != null) {
//                    data.put("branchCustomersDTOS",branchCustomers.getResult());
//                }
//            } catch (Exception e) {
//                log.info("调拨预报单创建渲染 分公司客户API异常");
//                e.printStackTrace();
//            }
//
//
//            result.put("success",true);
//            result.put("result",data);
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.info("调拨预报单创建渲染异常 {} " , e.getMessage());
//            result.put("success",false);
//            result.put("message","调拨预报单创建渲染异常");
//        }
//
//        return result;
//    }
//
//
//    @Override
//    public Object async(AsyncRequest asyncRequest) {
//        JSONObject result = new JSONObject();
//        JSONObject data = new JSONObject();
//        JSONObject asyncJson = new JSONObject();
//        try {
//            log.info("调拨预报单创建异步 请求参数 {} ", JSON.toJSONString(asyncRequest));
//            JSONObject request = (JSONObject)JSONObject.toJSON(asyncRequest.getRequest());
//
//            JSONObject fieldsJson = new JSONObject();
//            if (request != null) {
//                if (request.get("fields") != null) {
//                    fieldsJson = request.getJSONObject("fields");
//                    if (fieldsJson.getJSONObject("bizModel") != null) {
//                        data = fieldsJson.getJSONObject("bizModel").getJSONObject("result");
//                    }
//                    asyncJson = fieldsJson.getJSONObject("asyncJson");
//                }
//            }
//
//            if (asyncJson.get("type") != null && asyncJson.get("applyOrg") != null) {
//                try {
//                    //收货仓
//                    QueryReceivingWarehouseByTypeRequest queryReceivingWarehouseByTypeRequest = new QueryReceivingWarehouseByTypeRequest();
//                    queryReceivingWarehouseByTypeRequest.setType(fieldsJson.getString("type"));
//                    queryReceivingWarehouseByTypeRequest.setApplyOrgId(asyncJson.getString("applyOrg"));
//                    log.info("调拨预报单创建异步 收货仓API入参 {} ", JSONObject.toJSONString(queryReceivingWarehouseByTypeRequest));
//                    Result<List<DeliveryWarehouseChoiceDTO>> forecastWarehouseResult = forecastWarehouseService.queryReceivingWarehouseByType(queryReceivingWarehouseByTypeRequest);
//                    log.info("调拨预报单创建异步 收货仓API出参 {} ", JSONObject.toJSONString(forecastWarehouseResult));
//                    data.put("receivingWarehouse", forecastWarehouseResult.getResult());
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//            }
//            if (fieldsJson.get("type") != null) {
//                try {
//                    //发货仓
//                    QueryDeliveryWarehouseByTypeRequest queryDeliveryWarehouseByTypeRequest = new QueryDeliveryWarehouseByTypeRequest();
//                    queryDeliveryWarehouseByTypeRequest.setType(fieldsJson.getString("type"));
//                    log.info("调拨预报单创建异步 发货仓API入参 {} ",JSONObject.toJSONString(queryDeliveryWarehouseByTypeRequest));
//                    Result<List<DeliveryWarehouseChoiceDTO>> deliveryWarehouse = forecastWarehouseService.queryDeliveryWarehouseByType(queryDeliveryWarehouseByTypeRequest);
//                    log.info("调拨预报单创建异步 发货仓API出参 {} ",JSONObject.toJSONString(deliveryWarehouse));
//                    data.put("deliveryWarehouse",deliveryWarehouse.getResult());
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//            data.put("asyncJson",asyncJson);
//
//            result.put("success",true);
//            result.put("result",data);
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.info("调拨预报单创建异步渲染 异常 {}", e.getMessage());
//            result.put("success",false);
//            result.put("message",e.getMessage() != null ? e.getMessage() : "调拨预报单创建异步渲染异常");
//        }
//
//
//        log.info("调拨预报单创建异步渲染 出参 {} ", JSON.toJSONString(result));
//        return result;
//    }
//
//
//    @Override
//    public Object submit(SubmitRequest submitRequest) {
//        log.info("调拨预报单创建提交 请求参数 {} " , JSON.toJSONString(submitRequest));
//        JSONObject result = new JSONObject();
//        try {
//            JSONObject request = (JSONObject)JSONObject.toJSON(submitRequest.getRequest());
//
//            JSONObject bizModel = null;
//            String submitType = null;
//            JSONObject submitFields = null;
//            if (request != null) {
//                if (request.get("fields") != null) {
//                    submitType  = request.getJSONObject("fields").getString("submitType");
//                    submitFields = request.getJSONObject("fields").getJSONObject("submitFields");
//                    bizModel = request.getJSONObject("fields").getJSONObject("bizModel");
//                }
//            }
//
//            if (submitFields != null) {
//                Result<AllocateApplyOrderDetailDTO> allocateApplyOrderDetailDTOResult = allocateApplyOrderSubmit(submitFields,submitType);
//                if (!allocateApplyOrderDetailDTOResult.isSuccess()) {
//                    result.put("success",false);
//                    result.put("message",allocateApplyOrderDetailDTOResult.getMessage());
//                    return result;
//                }
//                if (bizModel != null) {
//                    bizModel.getJSONObject("result").put("detailData",allocateApplyOrderDetailDTOResult.getResult());
//                }
//            }
//
//            if ("submit".equals(submitType)) {
//                result.put("message","提交成功");
//            } else if ("save".equals(submitType)) {
//                result.put("message","保存成功");
//            }
//            result.put("success",true);
//            if ("save".equals(submitType)) {
//                result.put("message","保存成功");
//            } else if ("submit".equals(submitType)) {
//                result.put("message","提交成功");
//            }
//            result.put("result",bizModel.get("result"));
//        } catch (Exception e) {
//            log.info("调拨预报单创建提交 异常 {} " , e.getMessage());
//            e.printStackTrace();
//            result.put("success",false);
//        }
//        return result;
//    }
//
//
//    public Result<AllocateApplyOrderDetailDTO> allocateApplyOrderSubmit(JSONObject submitFields, String submitType) {
//        Result<AllocateApplyOrderDetailDTO> allocateApplyOrderDetailResult = new Result<>();
//        try {
//            Result<Boolean> checkResult = checkParams(submitFields,submitType);
//            if (!checkResult.isSuccess()) {
//                allocateApplyOrderDetailResult.setMessage(checkResult.getMessage());
//                allocateApplyOrderDetailResult.setSuccess(false);
//                return allocateApplyOrderDetailResult;
//            }
//            String  code = submitFields.getString("code");
//            Long id = submitFields.getLong("id");
//            if (code == null) {
//                //未创建
//                AllocateApplyOrderCreateDTO allocateApplyOrderCreateDTO = new AllocateApplyOrderCreateDTO();
//                allocateApplyOrderCreateDTO.setIsDTC(false);
//                //小程序创建标识
//                allocateApplyOrderCreateDTO.setIsAppCreate(true);
//                allocateApplyOrderCreateDTO.setApplyOrgId(submitFields.getLong("applyOrg"));
//                allocateApplyOrderCreateDTO.setType(submitFields.getInteger("type"));
//                allocateApplyOrderCreateDTO.setRemark(submitFields.getString("remark"));
//
//
//                if (submitFields.get("hopeDeliveryTime") != null) {
//                    allocateApplyOrderCreateDTO.setHopeDeliveryTime(new Date(submitFields.getLong("hopeDeliveryTime")));
//                }
//                allocateApplyOrderCreateDTO.setShipMethod(submitFields.getString("shipMethod"));
//                allocateApplyOrderCreateDTO.setGoodsGroup(submitFields.getInteger("goodsGroup"));
//                allocateApplyOrderCreateDTO.setShipWarehouseId(submitFields.getString("shipWarehouseId"));
//                allocateApplyOrderCreateDTO.setReceiveWarehouseId(submitFields.getInteger("receiveWarehouseId"));
//
//                try {
//                    if (submitFields.getInteger("receiveWarehouseId") != null) {
//                        QueryCargoZoneByIdRequest queryCargoZoneByIdRequest = new QueryCargoZoneByIdRequest();
//                        queryCargoZoneByIdRequest.setCargoZoneIdList(Lists.newArrayList(String.valueOf(submitFields.getInteger("receiveWarehouseId"))));
//                        QueryCargoZoneByIdResponse queryCargoZoneByIdResponse = unifiedInventoryService.queryCargoZoneById(queryCargoZoneByIdRequest);
//                        if (Objects.nonNull(queryCargoZoneByIdResponse)&& CollectionUtils.isNotEmpty(queryCargoZoneByIdResponse.getResult())) {
//                            Map<String, String> result = (Map<String, String>) queryCargoZoneByIdResponse.getResult().get(0);
//                            //总部内部售达方编号
//                            allocateApplyOrderCreateDTO.setSapInternalSalesBPCode(result.get("sapInternalSalesBPCode"));
//                            //总部内部送达方编号
//                            allocateApplyOrderCreateDTO.setSapInternalDeliveryBPCode(result.get("sapInternalDeliveryBPCode"));
//                            //总部售达方编号
//                            allocateApplyOrderCreateDTO.setSapSalesBPCode(result.get("sapSaleBPCode"));
//                            //总部送达方编号
//                            allocateApplyOrderCreateDTO.setSapDeliveryBPCode(result.get("sapDeliveryBPCode"));
//                        }
//                    }
//                } catch (Exception e) {
//                    log.info("调拨预报单创建提交 unifiedInventoryService.queryCargoZoneById异常");
//                    e.printStackTrace();
//                }
//
//
//                log.info("调拨预报单创建提交 调创建API参数 {} " , JSONObject.toJSONString(allocateApplyOrderCreateDTO));
//                Result<AllocateApplyOrderDetailDTO> allocateApplyOrderDetailDTOResult = allocateApplyOrderWriteService.createAllocateApplyOrder(allocateApplyOrderCreateDTO);
//                if (allocateApplyOrderDetailDTOResult.isSuccess()) {
//                    code = allocateApplyOrderDetailDTOResult.getResult().getCode();
//                    id = allocateApplyOrderDetailDTOResult.getResult().getId();
//                } else {
//                    allocateApplyOrderDetailResult.setMessage(allocateApplyOrderDetailDTOResult.getMessage());
//                    allocateApplyOrderDetailResult.setSuccess(false);
//                    return allocateApplyOrderDetailResult;
//                }
//            }
//
//            AllocateApplyOrderUpdateDTO allocateApplyOrderUpdateDTO = new AllocateApplyOrderUpdateDTO();
//            allocateApplyOrderUpdateDTO.setId(id);
//            allocateApplyOrderUpdateDTO.setCode(code);
//            allocateApplyOrderUpdateDTO.setRemark(submitFields.getString("remark"));
//            if (submitFields.get("hopeDeliveryTime") != null) {
//                allocateApplyOrderUpdateDTO.setHopeDeliveryTime(new Date(submitFields.getLong("hopeDeliveryTime")));
//            }
//            allocateApplyOrderUpdateDTO.setShipMethod(submitFields.getString("shipMethod"));
//            allocateApplyOrderUpdateDTO.setShipWarehouseId(submitFields.getString("shipWarehouseId"));
//            //不传值，提交接口底层获取不到会nep
//            allocateApplyOrderUpdateDTO.setIsDTC(false);
////            allocateApplyOrderUpdateDTO.setType(submitFields.getString("type"));
////            allocateApplyOrderUpdateDTO.setGoodsGroup(submitFields.getString("goodsGroup"));
//            //工厂直发编辑
//            if (submitFields.getBooleanValue("factory")) {
//                //编辑状态下，客户地址，客户名称，分公司客户不可编辑
////                allocateApplyOrderUpdateDTO.setCustomerAddress(submitFields.getString("customerAddress"));
////                allocateApplyOrderUpdateDTO.setCustomer(submitFields.getString("customer"));
//                allocateApplyOrderUpdateDTO.setIsDTC(true);
//            } else {
//                allocateApplyOrderUpdateDTO.setReceiveWarehouseId(submitFields.getInteger("receiveWarehouseId"));
//            }
//
//            List<AllocateApplyOrderDetailCreateDTO> list = new ArrayList<>();
//            if (submitFields.get("submitGoods") != null) {
//                JSONArray jsonArray = submitFields.getJSONArray("submitGoods");
//                if (CollectionUtils.isNotEmpty(jsonArray)) {
//                    for (Object goodsObj : jsonArray) {
//                        JSONObject goods = (JSONObject) JSONObject.toJSON(goodsObj);
//                        AllocateApplyOrderDetailCreateDTO allocateApplyOrderDetailCreateDTO = new AllocateApplyOrderDetailCreateDTO();
//                        allocateApplyOrderDetailCreateDTO.setTitle(goods.getString("goodsName"));
//                        allocateApplyOrderDetailCreateDTO.setApplyQuantity(goods.getInteger("goodsNum"));
//                        allocateApplyOrderDetailCreateDTO.setGoodsId(goods.getString("id"));
//                        allocateApplyOrderDetailCreateDTO.setScItemId(goods.getString("goodsCode"));
//                        allocateApplyOrderDetailCreateDTO.setRemark(goods.getString("remark"));
//                        allocateApplyOrderDetailCreateDTO.setLineNo(goods.getInteger("goodsDetailsLine"));
//                        list.add(allocateApplyOrderDetailCreateDTO);
//                    }
//                }
//
//            }
//            allocateApplyOrderUpdateDTO.setList(list);
//
//            log.info("调拨预报单创建提交 入参 {} " , JSON.toJSONString(allocateApplyOrderUpdateDTO));
//
//            Result<Boolean> updateAllocateApplyOrderResult = null;
//            if ("submit".equals(submitType)) {
//                updateAllocateApplyOrderResult =  allocateApplyOrderWriteService.submitAllocateApplyOrder(allocateApplyOrderUpdateDTO);
//            } else if ("save".equals(submitType)) {
//                updateAllocateApplyOrderResult =  allocateApplyOrderWriteService.updateAllocateApplyOrder(allocateApplyOrderUpdateDTO);
//            }
//            if (!updateAllocateApplyOrderResult.isSuccess()) {
//                allocateApplyOrderDetailResult.setSuccess(false);
//                allocateApplyOrderDetailResult.setMessage(updateAllocateApplyOrderResult != null ? updateAllocateApplyOrderResult.getMessage() : "保存提交失败");
//                return allocateApplyOrderDetailResult;
//            }
//
//            QueryAllocateApplyOrderRequest queryAllocateApplyOrderRequest = new QueryAllocateApplyOrderRequest();
//            queryAllocateApplyOrderRequest.setCode(code);
//            Result<AllocateApplyOrderDetailDTO> callApiResult = allocateApplyOrderReadService.queryAllocateApplyOrderByCode(queryAllocateApplyOrderRequest);
//
//            return callApiResult;
//        } catch (Exception e) {
//            log.info("调拨预报单创建提交 请求RPC异常 {} " , e.getMessage());
//            e.printStackTrace();
//            allocateApplyOrderDetailResult.setSuccess(false);
//            allocateApplyOrderDetailResult.setMessage("保存提交失败");
//        }
//        return allocateApplyOrderDetailResult;
//    }
//
//    public Result<Boolean> checkParams(JSONObject submitFields, String submitType) {
//        Result<Boolean> result = new Result<>();
//        result.setSuccess(true);
//        if (submitFields.getInteger("type") == null) {
//            result.setMessage("单据类型必填");
//            result.setSuccess(false);
//            return result;
//        } else if (submitFields.getString("shipWarehouseId") == null) {
//            result.setMessage("发货仓必填");
//            result.setSuccess(false);
//            return result;
//        }  else if (submitFields.getString("hopeDeliveryTime") == null) {
//            result.setMessage("期望交货日期必填");
//            result.setSuccess(false);
//            return result;
//        }
//
//        //工厂直发调拨预报单
//        if (submitFields.getBooleanValue("factory")) {
//            if (submitFields.getString("customer") == null) {
//                result.setMessage("客户名称必填");
//                result.setSuccess(false);
//                return result;
//            }
//            if (submitFields.getString("customerAddress") == null) {
//                result.setMessage("客户地址必填");
//                result.setSuccess(false);
//                return result;
//            }
//        } else {
//            if (submitFields.getInteger("goodsGroup") == null) {
//                result.setMessage("货品组必填");
//                result.setSuccess(false);
//                return result;
//            }
//            if (submitFields.getInteger("receiveWarehouseId") == null) {
//                result.setMessage("收货仓必填");
//                result.setSuccess(false);
//                return result;
//            }
//        }
//
//
//
//        if (submitFields.get("submitGoods") == null || org.apache.commons.collections.CollectionUtils.isEmpty(submitFields.getJSONArray("submitGoods"))) {
//            result.setMessage("货品明细不能为空");
//            result.setSuccess(false);
//            return result;
//        }
//
//        return result;
//    }
//
//    public List<QueryGoodsListResponse> buildGoodsList(List<QueryGoodsListResponse> queryGoodsList,List goodsIdList) {
//        if (org.apache.commons.collections.CollectionUtils.isEmpty(goodsIdList)) {
//            return queryGoodsList;
//        }
//        if (org.apache.commons.collections.CollectionUtils.isEmpty(queryGoodsList)) {
//            return queryGoodsList;
//        }
//        Set<String> goodsIdSet = new HashSet();
//        for (Object goodsId : goodsIdList) {
//            goodsIdSet.add(goodsId.toString());
//        }
//        List list = new ArrayList();
//        for (String goodsId : goodsIdSet) {
//            boolean flg = false;
//            for (QueryGoodsListResponse queryGoodsListResponse : queryGoodsList) {
//                flg = false;
//                if (org.apache.commons.collections.CollectionUtils.isNotEmpty(queryGoodsListResponse.getGoodsList())) {
//                    for (Object goodsObj : queryGoodsListResponse.getGoodsList()) {
//                        JSONObject goodsJson = (JSONObject) JSONObject.toJSON(goodsObj);
//                        if (goodsId.equals(goodsJson.getString("id"))) {
//                            list.add(goodsObj);
//                            flg = true;
//                            break;
//                        }
//                    }
//                }
//                if (flg) break;
//            }
//        }
//        if (CollectionUtils.isEmpty(list)) {
//            return queryGoodsList;
//        }
//        QueryGoodsListResponse queryGoodsListResponse = new QueryGoodsListResponse();
//        //端上构造的虚假常用货品类目,库中无该类目
//        queryGoodsListResponse.setLabel("常用货品");
//        queryGoodsListResponse.setGoodsList(list);
//
//        List<QueryGoodsListResponse> queryGoodsListResponseList = new ArrayList<>();
//        queryGoodsListResponseList.add(queryGoodsListResponse);
//        queryGoodsListResponseList.addAll(queryGoodsList);
//
//        return queryGoodsListResponseList;
//    }
//
//
//}
